package com.tuyan.aixiang.component;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.tuyan.aixiang.R;
import com.tuyan.aixiang.common.lang.VoidFunction;
import com.tuyan.aixiang.model.YsDevice;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SensorItem extends RelativeLayout {

    @BindView(R.id.tv_title)
    TextView tvTitle;

    @BindView(R.id.iv_bg)
    ImageView ivBg;


    public SensorItem(Context context) {
        this(context, null);
    }

    public SensorItem(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public SensorItem(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        View contentView = LayoutInflater.from(context).inflate(R.layout.sensor_item, this);
        ButterKnife.bind(contentView, this);
    }

    public void setup(YsDevice sensor){
//        setBackgroundResource(sensor.getBanner());
        Glide.with(getContext()).load(sensor.getDevicePicUrl()).into(ivBg);
        tvTitle.setText(sensor.getDeviceName());
    }

    public void onClick(VoidFunction function) {
        setOnClickListener(v -> {
            function.call();
        });
    }
}
